﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;

namespace InkRun
{
    class Obstacle : GameObject
    {

        public static Texture2D obstacleSprite { get; set; }
        public float scale;
        public bool touchingOtherobstacle;
        public enum ObstacleState
        {
            Alive,
            Dead
        }

        /// <summary>
        /// The unique ID of the obstacle
        /// </summary>
        public int obstacleID { get; set; }

        public ObstacleState obstacleState;

        new public Vector2 velocity;



        public float timeTillNextShot;

        public int upKey, downKey, leftKey, rightKey, fireKey;
        public Color color;


        public int Lives { get; set; }
        public bool NoLivesLeft { get; set; }

        public Obstacle(Vector2 position)
            : base(position)
        {

            scale = 0.5f;
            sizeInPixels = new Vector2(scale * obstacleSprite.Bounds.Width, scale * obstacleSprite.Bounds.Height);
            obstacleState = ObstacleState.Alive;
            velocity = new Vector2(-2.0f, 0.0f);
            SetUpobstacle();
        }

        public Obstacle(int obstacleID, Vector2 Position)
            : base(Position)
        {
            this.obstacleID = obstacleID;
            touchingOtherobstacle = false;

            // Lives

            Lives = 3;
            NoLivesLeft = false;
        }

        public void SetUpobstacle()
        {
        }

        public void Resetobstacle()
        {

        }

        public override void Update(GameTime gameTime)
        {

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            switch (obstacleState)
            {
                case ObstacleState.Alive:
                    if (IsOffscreen())
                    {
                        obstacleState = ObstacleState.Dead;
                    }
                    position += velocity;

                    break;
                case ObstacleState.Dead:
                    Die();

                    break;
                default:
                    break;
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            switch (obstacleState)
            {
                case ObstacleState.Alive:
                    spriteBatch.Draw(obstacleSprite, position, null, Color.White, 0, new Vector2(obstacleSprite.Bounds.Center.X, obstacleSprite.Bounds.Center.Y), scale, SpriteEffects.None, 0);

                    break;
                case ObstacleState.Dead:

                    break;
                default:
                    break;
            }
        }

        public override void Die()
        {
            base.Die();
        }
    }
}
